/**
 * Created by jiangyukun on 2016/5/23.
 */

'use strict';

app.controller('CommunityPostController', function ($scope, iHttp, $uibModal, DTOptionsBuilder, DTColumnBuilder) {

    $scope.dtOptions = DTOptionsBuilder.newOptions()
        .withOption('lengthChange', false)
        .withOption('searching', false)
        .withOption('ajax', {dataSrc: 'data'})
        .withOption('serverSide', true)
        .withOption('serverData', getServerData);


    $scope.dtColumns = [
        DTColumnBuilder.newColumn('id').withTitle('ID').notVisible(),
        DTColumnBuilder.newColumn('whichBoard').withTitle('板块'),
        DTColumnBuilder.newColumn('postUser').withTitle('发表人'),
        DTColumnBuilder.newColumn('isAnonymous').withTitle('匿名'),
        DTColumnBuilder.newColumn('postContent').withTitle('内容'),
        DTColumnBuilder.newColumn('postPicture').withTitle('图片'),
        DTColumnBuilder.newColumn('scanCount').withTitle('浏览'),
        DTColumnBuilder.newColumn('likeCount').withTitle('点赞'),
        DTColumnBuilder.newColumn('commentCount').withTitle('评论'),
        DTColumnBuilder.newColumn('postDateTime').withTitle('发表时间'),
        DTColumnBuilder.newColumn('deleteByUser').withTitle('被删除')
    ];


    $scope.addPost = addPost;
    $scope.lookPost = lookPost;
    $scope.deletePost = deletePost;


    function getServerData(source, data, callback) {
        iHttp.get('mock/json/community-post.json', {data: data}).then(function (result) {
            callback(result.data);
        });
    }

    function addPost() {
        $uibModal.open({
            templateUrl: 'tpl/community/post/add_post_dialog.html',
            controller: 'AddBoardController'
        })
    }

    function lookPost() {
        $uibModal.open({
            templateUrl: 'tpl/community/post/look_post_dialog.html',
            controller: 'LookBoardController'
        })
    }

    function deletePost() {
        $uibModal.open({
            templateUrl: 'tpl/community/look_board_dialog.html',
            controller: 'LookBoardController'
        })
    }
});

app.controller('AddBoardController', function ($scope, $uibModalInstance) {
    $scope.close = close;


    function close() {
        $uibModalInstance.close();
    }
});

app.controller('LookBoardController', function ($scope, $uibModalInstance) {
    $scope.close = close;


    function close() {
        $uibModalInstance.close();
    }
});